export const Util = {

  YouTubeGetID: (url) => {
    var ID = '';
    url = url.replace(/(>|<)/gi, '').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
    if (url[2] !== undefined) {
      ID = url[2].split(/[^0-9a-z_\-]/i);
      ID = ID[0];
    }
    else {
      ID = url;
    }
    return ID;
  },

  convertSecondsToDateTime(secs) {
    var t = new Date(1970, 0, 1); // Epoch
    t.setSeconds(secs);
    return t;
  },

  getCurrencySymbol(currency) {
    var currency_symbols = {
      'USD': '$', // US Dollar
      'EUR': '€', // Euro
      'CRC': '₡', // Costa Rican Colón
      'GBP': '£', // British Pound Sterling
      'ILS': '₪', // Israeli New Sheqel
      'INR': '₹', // Indian Rupee
      'JPY': '¥', // Japanese Yen
      'KRW': '₩', // South Korean Won
      'NGN': '₦', // Nigerian Naira
      'PHP': '₱', // Philippine Peso
      'PLN': 'zł', // Polish Zloty
      'PYG': '₲', // Paraguayan Guarani
      'THB': '฿', // Thai Baht
      'UAH': '₴', // Ukrainian Hryvnia
      'VND': '₫', // Vietnamese Dong
    };
    return currency_symbols[currency];
  }

}

export const formatDate = (timestamp, format) => {
  let months = [
    "Jan",
    "Feb",
    "Mar",
    "Apr",
    "May",
    "Jun",
    "Jul",
    "Aug",
    "Sep",
    "Oct",
    "Nov",
    "Dec",
  ];
  let timestamps = null
  if(timestamp.split(" ").length>1){
    timestamps = Math.round(new Date(timestamp).getTime())
  } else {
    timestamps = Math.round(timestamp)
  }
  const date = new Date(timestamps);
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();

  format = format.replace('yyyy', year);
  format = format.replace('MM', month < 10 ? '0' + month : month);
  format = format.replace('dd', day < 10 ? '0' + day : day);
  
  let aa = day < 10 ? '0' + day : months[month] + " " + day + " " + year

  return aa;
}
